package com.itemdoc.organ.util;

import org.jasypt.encryption.StringEncryptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/Jasypt")
public class Jasypt {
	@Autowired
	private StringEncryptor Encryptor;
	/**
	 * localhost/Jasypt/encrypt/123456
	 * @param value
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping(value = "/encrypt/{value}")
	public Result encrypt(@PathVariable String value) throws Exception {
		try {
			 String encrypt= Encryptor.encrypt(value);
			 System.out.println(encrypt);
			 return new Result(200, "生成成功！", encrypt);
		} catch (Exception e) {
			System.err.println("相应超时！");
		}
	    return new Result(2001, "生成失败！");
	}
}
